<?php
/**
 * Created by PhpStorm.
 * User: kcj
 * Date: 2017/5/26
 * Time: 23:14
 */

require_once "api.php";

require_once "./../application/index/controller/Index.php";

require_once "./../application/common/RedisDB.php";
use app\common\RedisDB;

use app\index\controller;
$redis = RedisDB::factory("wtimer");
while (true) {
    $time = time();
    $prefix = $redis->getOption(\Redis::OPT_PREFIX);
    $keys = $redis->keys("*");
    foreach ($keys as $k) {
        $msg = substr($k, strlen($prefix));
        $v = $redis->get($msg);
        if (abs($time - $v) < 0.8) {
            $redis->del($msg);
            $strs = explode("/", $msg);
            if(count($strs)<2)continue;
            $control = "app\\index\\controller\\".ucfirst($strs[0]);
            $func = $strs[1];
            $cs = [];
            foreach($strs as $k=>$v)
            {
                if($k%2==1 && $k>2)
                $cs[]=$v;
            }
            $c = new $control();
            $c->$func(...$cs);
        } else if ($time - $v > 1) {
            $redis->del($msg);
        }
        sleep(1);
    }
}